|
1
|
|
|
/** |
|
2
|
|
|
dark |
|
3
|
|
|
Component that handles dark matter and second prestige logic. |
|
4
|
|
|
It handles dark matter production and dark upgrades. |
|
5
|
|
|
A second prestige resets the progress of all elements with exotic |
|
6
|
|
|
matter and produces dark matter. |
|
7
|
|
|
|
|
8
|
|
|
@namespace Components |
|
9
|
|
|
*/ |
|
10
|
|
|
'use strict'; |
|
11
|
|
|
|
|
12
|
|
|
angular.module('game').component('dark', { |
|
13
|
|
|
templateUrl: 'views/dark.html', |
|
14
|
|
|
controller: 'ct_dark', |
|
15
|
|
|
controllerAs: 'ct' |
|
16
|
|
|
}); |
|
17
|
|
|
|
|
18
|
|
|
angular.module('game').controller('ct_dark', ['state', 'format', 'visibility', 'upgrade', 'data', 'util', |
|
19
|
|
|
function(state, format, visibility, upgrade, data, util) { |
|
20
|
|
|
let ct = this; |
|
21
|
|
|
ct.state = state; |
|
22
|
|
|
ct.data = data; |
|
23
|
|
|
ct.util = util; |
|
24
|
|
|
ct.format = format; |
|
25
|
|
|
ct.cache = { |
|
26
|
|
|
breakdown: {} |
|
27
|
|
|
}; |
|
28
|
|
|
|
|
29
|
|
|
ct.update = function(player) { |
|
30
|
|
|
refresh(player); |
|
31
|
|
|
}; |
|
32
|
|
|
|
|
33
|
|
|
/* Refreshes the values in the cache */ |
|
34
|
|
|
function refresh(player) { |
|
35
|
|
|
ct.cache.breakdown = {}; |
|
36
|
|
|
for (let element in data.elements) { |
|
37
|
|
|
let exotic = data.elements[element].exotic; |
|
38
|
|
|
if (!player.resources[exotic].unlocked || !player.statistics.dark_run[exotic]) { |
|
39
|
|
|
continue; |
|
40
|
|
|
} |
|
41
|
|
|
let number = player.statistics.dark_run[exotic]; |
|
42
|
|
|
let darkProduction = util.prestigeProduction(number, data.constants.DARK_START, data.constants.DARK_STEP); |
|
43
|
|
|
ct.cache.breakdown[exotic] = Math.round(Math.max(0, darkProduction)); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
ct.darkProduction = function() { |
|
48
|
|
|
let production = 0; |
|
49
|
|
|
for (let resource in ct.cache.breakdown) { |
|
50
|
|
|
production += ct.cache.breakdown[resource]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return production; |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
ct.darkPrestige = function(player) { |
|
57
|
|
|
let production = ct.darkProduction(); |
|
58
|
|
|
|
|
59
|
|
|
util.addResource(player, 'all_time', 'dark_matter', production, state); |
|
60
|
|
|
|
|
61
|
|
|
for (let key in data.elements) { |
|
62
|
|
|
let element = data.elements[key]; |
|
63
|
|
|
player.resources[element.exotic].number = 0; |
|
64
|
|
|
if (!player.exotic_upgrades[key]) { |
|
65
|
|
|
continue; |
|
66
|
|
|
} |
|
67
|
|
|
for (let up in data.exotic_upgrades) { |
|
68
|
|
|
player.exotic_upgrades[key][up] = false; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
for (let slot of player.element_slots) { |
|
72
|
|
|
if (!slot) { |
|
73
|
|
|
continue; |
|
74
|
|
|
} |
|
75
|
|
|
upgrade.resetElement(player, slot.element); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
for (let i in player.element_slots) { |
|
79
|
|
|
player.element_slots[i] = null; |
|
80
|
|
|
} |
|
81
|
|
|
player.statistics.exotic_run = {}; |
|
82
|
|
|
player.statistics.dark_run = {}; |
|
83
|
|
|
}; |
|
84
|
|
|
|
|
85
|
|
|
ct.buyDarkUpgrade = function(name, player) { |
|
86
|
|
|
let upgrades = player.dark_upgrades; |
|
87
|
|
|
let price = data.dark_upgrades[name].price; |
|
88
|
|
|
let currency = 'dark_matter'; |
|
89
|
|
|
upgrade.buyUpgrade(player, |
|
90
|
|
|
upgrades, |
|
91
|
|
|
data.dark_upgrades[name], |
|
92
|
|
|
name, |
|
93
|
|
|
price, |
|
94
|
|
|
currency); |
|
95
|
|
|
}; |
|
96
|
|
|
|
|
97
|
|
|
ct.visibleDarkUpgrades = function(player) { |
|
98
|
|
|
return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0, null, player); |
|
99
|
|
|
}; |
|
100
|
|
|
|
|
101
|
|
|
// here we receive not the name of the element, but the index in the element_slots |
|
102
|
|
|
function isDarkUpgradeVisible(name, index, player) { |
|
103
|
|
|
return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name], player); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
state.registerUpdate('dark', ct.update); |
|
107
|
|
|
refresh(state.player); |
|
108
|
|
|
} |
|
109
|
|
|
]); |
|
110
|
|
|
|